package com.pzhuweb.sgblog.controller;

import com.pzhuweb.sgblog.domain.dto.TagListDto;
import com.pzhuweb.sgblog.domain.enums.AppHttpCodeEnum;
import com.pzhuweb.sgblog.domain.vo.TagVo;
import com.pzhuweb.sgblog.exception.SystemException;
import com.pzhuweb.sgblog.service.TagService;
import com.pzhuweb.sgblog.domain.utils.ResponseResult;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 鄧浩奇
 * @classname TagController
 * @description
 * @since 2023/8/13 16:33
 **/

@RestController
@RequestMapping("/content/tag")
public class TagController {

    @Resource
    private TagService tagService;

    /*
     * 查询标签
     * */
    @GetMapping("/list")
    public ResponseResult<?> list(Integer pageNum, Integer pageSize, TagListDto tagListDto) {
        return tagService.getTagList(pageNum, pageSize, tagListDto);
    }

    /*
     * 新增标签
     * */
    @PostMapping()
    public ResponseResult<?> tag(@RequestBody TagListDto tagListDto) {
        if (!(StringUtils.hasText(tagListDto.getName()) && StringUtils.hasText(tagListDto.getRemark()))) {
            throw new SystemException(AppHttpCodeEnum.LIST_IS_NULL);
        }
        return tagService.tag(tagListDto);
    }

    /*
     * 删除标签
     * */
    @DeleteMapping("/{id}")
    public ResponseResult<?> deleteTags(@PathVariable("id") List<String> ids) {
        return tagService.deleteTags(ids);
    }

    /*
    * 获取标签信息
    * */
    @GetMapping("/{id}")
    public ResponseResult<?> getTagInfo(@PathVariable("id") Long id) {
        return tagService.getTagInfo(id);
    }

    /*
    * 修改标签信息
    * */
    @PutMapping()
    public ResponseResult<?> updateTag(@RequestBody TagVo tagVo) {
        return tagService.updateTag(tagVo);
    }
}
